import java.util.Scanner;
public class homeWork {
    static Scanner sc;
    //判断是否为闰年，闰年返回值1.
    static public int isrunyera(int myear) {
      return (myear % 400 == 0 || myear % 4 == 0 && myear % 100 != 0) ? 1 : 0;
    }
    //计算两年之间的天数
    static public int countYearDays(int oyear, int iyear) {
        int myear, sum = 0;
        for (myear = oyear; myear < iyear; myear++) {
            sum = sum + 365 + isrunyera(myear);
        }
        return sum;
    }
    // 1. 已知1900年一月一号是星期一，求今年有多少个黑色星期五(13号是星期五即是黑色星期五)
    static public void blackFri() {
        int oyear = 1900, iyear =2017,i;
        System.out.printf("请输入要计算的年：");
        iyear = sc.nextInt();
        int sum = countYearDays(oyear, iyear) + 13;
        for (i = 1; i < 12; i++) {
            switch (i) {
               case 1:
                   break;
               case 11:
               case 4:
               case 6:
               case 8:
               case 9:
               case 2:
                    sum = sum + 31;
                    break;
               case 7:
               case 10:
               case 12:
               case 5:
                    sum = sum + 30;
                    break;
               default:
                    sum = sum + 28 + isrunyera(iyear);
                    break;

            }
           if(sum % 7 == 5) {
               System.out.printf("%d年 %d月 是黑色星期五\n", iyear, i);
           }
        }
     }
    //从1月1日到当月1日的天数
    static public int countMonthDays(int month, int year) {
    int sum = (month - 1) * 30 + month / 2;
    sum += (month == 9 || month == 11)? 1: 0;
    return (month > 2)? sum - 2 + isrunyera(year): sum;
    }
//2. 张三从2000年1月1号开始过着三天打鱼两天晒网的日子，指定年月日求在打鱼还是晒网
    static public void w2() {
        int sum = 0, year = 2000, month = 1, day = 1, oyear = 2000;
        while(true) {
            System.out.printf("请输入要计算的年：");
            year = sc.nextInt();
            System.out.printf("请输入要计算的月：");
            month = sc.nextInt();
            System.out.printf("请输入要计算的日：");
            day = sc.nextInt();
            if (year < 2000 || day == -1) {
                break;
            }
            else if (!valid(year, month, day)){
                continue;
            }
            else {
        sum = countYearDays(oyear, year) + countMonthDays(month, year) + day - 1;
            if (sum % 5 < 3) {
            System.out.printf("%d年 %d月 %d日张三在打鱼\n", year, month, day);
            }
            else {
            System.out.printf("%d年 %d月 %d日张三在晒网\n", year, month, day);
            }
            }
        }
    }
    //输入的日期是否有效
    static public boolean valid(int year, int month, int day) {
        if (year < 0 || year > 9999 || month < 1 || month > 12
              || (month == 4 || month == 6 || month == 9 || month == 11
                   && day > 30) || (month == 2 && day > 28 + isrunyera(year)))
            return false;
        return true;
    }
    //判断是否为回文数
    static public boolean isPalindrome(long num) {
        long oldnum = num, sum = 0;
        while(num > 0) {
            sum = sum * 10 + num % 10;
            num /= 10;
        }
        return (sum == oldnum)? true: false;
    }
    static public void palindrome() {
        while(true){
            System.out.printf("请输入一个数字：");
            long num = sc.nextLong();
            if (num == -1) {
                break;
            }
            else {
                if(isPalindrome(num)) {
                    System.out.printf("%d 是回文数字\n", num);
                }
                else {
                    System.out.printf("%d 不是回文数字\n", num);
                }
            }
        }
    }
    //转化大小写！
    static public void change() {
        char ch, ret;
        while (true) {
            System.out.printf("请输入一个字母：");
            ch = sc.next().charAt(0);
            if(ch == '/') {
                break;
            }
            else if(ch >= 'a' && ch <= 'z') {
                ret =(char)(ch - 32);
            }
            else if(ch >= 'A' && ch <= 'Z') {
                ret = (char)(ch + 32);
            }
            else {
                continue;
            }
                System.out.printf("%c <=> %c\n", ch, ret);
        }
    }
    static public void Select() {
        System.out.printf("请输入要执行第几题：");
        int i = sc.nextInt();
        switch(i) {
            case 1:
                System.out.println("指定年求是否有黑色星期五！");
                blackFri();
                break;
            case 2:
                System.out.println("求打鱼还是晒网/年小于2000或日等于-1退出");
                w2();
                break;
            case 3:
                System.out.println("是否为回文数！ -1 退出");
                palindrome();
                break;
            case 4:
                System.out.println("转化大小写字母 / 退出");
                change();
                break;
            case 0:
                break;
        }
    }
    static public void main(String [] args) {
        sc = new Scanner(System.in);
        Select();
    }
}
